<template>
    <div>
        <h1>机构列表</h1>
        机构名称:
        <input type="text" v-model="dataget.name">
        特色服务:
          <select v-model="dataget.tid">
                    <option value="0">请选择</option>
                    <option v-for="d in Bang":value=d.tid>{{d.tname  }}</option>
          </select>
          <input type="date"  v-model="dataget.time">
          <input type="button" class="btn btn-success" value="查询" @click="Show">
           <input type="button" class="btn btn-success" value="重置" @click="cz">
<table class="table">
    <thead>
        <tr>
            <td><input type="checkbox" v-model="selectshow" @change="Quan"></td>
            <td>编号</td>
            <td>图片</td>
            <td>特色服务</td>
            <td>发布时间</td>
            <td>地址</td>
            <td>手机号</td>
            <td>状态</td>
            <td>机构详情</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody v-for="d in showdata">
    <tr>
        <td><input  v-model="idarray" type="checkbox":value=d.id></td>
            <td>{{d.code  }}</td>
            <td><img style="width: 60px;height: 60px;":src="axios.defaults.baseURL+d.img" ></td>
            <td>{{d.tname  }}</td>
            <td>{{moment(d.statetime).format("YYY-MM-DD")  }}</td>
            <td>{{d.addr  }}</td>
            <td>{{d.phone  }}</td>
            <td>{{d.state==true?"已发布":"未发布"  }}</td>
            <td>{{d.ting  }}</td>
            <td>
                <input type="button" value="删除" @click="Del(d.id)">
                <input type="button" value="编辑" @click="Upd(d.id)">
            </td>
   </tr>
    </tbody>
    
</table>
一共{{ datacount.count  }}条 一共{{datacount.page  }}页 每页显示{{dataget.size }}条 当前{{dataget.index  }}页
<input type="button" value="首页" @click="fy(1)">
<input type="button" value="上一页" @click="fy(dataget.index-1)">
<input type="button" v-for="a in datacount.page":value="a" @click="fy(a)" >
<input type="button" value="下一页" @click="fy(dataget.index+1)">
<input type="button" value="尾页" @click="fy(datacount.page)">

<input type="button" value="批量修改" @click="Plshan">

    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
import moment from 'moment'
const router=useRouter()

//数组
const selectshow=ref(false);

const Quan=()=>{
    idarray.value=[];
    if(selectshow.value)
    {
        showdata.value.forEach((e)=>{
            idarray.value.push(e.id);
        })
    }
}


//批量数组
const idarray=ref([]);
//批量修改
const Plshan=()=>{
    if(idarray.value.length==0)
{
alert("请选择要删除的行")
return;
}
    if(confirm("确认发布吗?"))
    {
       axios.post("/api/Body/AddBody",{params:{idstring:idarray.value.toString()}}).then(res=>{
      if(res.data>0)
      {
        alert("批量发布成功")
        return
      }
      else
      {
         alert("发布失败")
      }
    })
    }
}


//编辑跳转页面
const Upd=(val:number)=>{
  router.push({path:"/Updbody",query:{id:val}})
}

//删除
const Del=(mid:number)=>{
    if(confirm("确认删除吗?"))
    {
        axios.delete("/api/Body/DeleteBody",{params:{id:mid}}).then(res=>{
            if(res.data>0)
            {
                alert("删除成功");
                Show()
            }
            else
            {
                alert("删除失败")
            }
        })
    }
}


//翻页
const fy=(a:any)=>{
  if(a>=1 && a<=datacount.value.page)
  {
    dataget.value.index=a;
    Show()
  }
}
//重置
const cz=()=>{
   dataget=ref({
    name:"",
    tid:0,
    time:"",
    index:1,
    size:3
})
   // dataget.value.name="";
   //  dataget.value.time="";
   // dataget.value.tid=0;
}

onMounted(()=>{
    Type();
    Show();
})

const Bang=ref([{
      "tid": 0,
    "tname": ""
}])
const Type=()=>{
    axios.get("/api/Type/GetTypes").then(res=>{
      Bang.value=res.data
    })
}

const showdata=ref([{
      "id": 2,
    "code": "",
    "img": "",
    "tid": 0,
    "statetime": "",
    "addr": "",
    "phone": "",
    "state": 0,
    "ting": "",
    "tname": ""
}])
const dataget=ref({
    name:"",
    tid:0,
    time:"",
    index:1,
    size:3
})
const datacount=ref({
   count:0,
   page:0
})
const Show=()=>{
    axios.get("/api/Body/ShowBody",{params:dataget.value}).then(res=>{
        showdata.value=res.data.page
        datacount.value.count=res.data.count
        datacount.value.page=Math.ceil(datacount.value.count/dataget.value.size)
    })
}



</script>

<style scoped>

</style>